// Copyright 2011 Bryan McKelvey, MIT License

/**
 * @fileoverview Methods for the popup
 * @author bryan.mckelvey@gmail.com (McKelvey Bryan)
 */

/**
 * A handful of methods for the popup
 * @constructor
 */
var Popup = (function(){
	/**
	 * Retrieves the background page
	 * @type function
	 */
	var bg = chrome.extension.getBackgroundPage();
	
	/**
	 * Determines the natural width of the page
	 * @type number
	 * @deprecated
	 */
	var naturalWidth = 0;
	
	var tbl = document.getElementById("table");
	
	return {
		/**
		 * Loads the popup, calling the methods to localize the page and draw
		 * all of the elements
		 * @return The current object
		 * @type Popup
		 */
		load: function(){
			Display.load({
				quotes: bg.Investor.exportJSON(),
				metrics: bg.Metrics.exportJSON(),
				settings: bg.Settings.exportJSON(),
				sources: bg.Sources.exportJSON(),
				translations: bg.Localizer.exportJSON()
			}).assign({
				chart: $('#cqChart'),
				dropdown: $('#cqDropdown'),
				table: $('#cqTable')
			});
			Display.table.draw();
			bg.Localizer.localize($(document));
			/*
		  if (bg.Investor.current() == undefined) {
		    bg.Investor.reset();
		  }
		  bg.Investor.createDropDown($('#dropdown')[0], tbl, false);
		  bg.Investor.drawTable($('#table')[0]);
		  */
		  bg.Sources.$div = $('#chart');
		  // setInterval(Popup.updateTable, 2000);
			return this;
		},
		
		/**
		 * Updates the quote table
		 * @returns The current object
		 * @type Popup
		 */
		updateTable: function() {
		  bg.Investor.current().updateTable($('#table')[0]);
			return this;
		}
	}	
})();

Popup.load();
